#ifndef Entity_H
#define Entity_H

#include <string>
#include <conio.h>
#include <d3dx9.h>
#include <d3d9.h>
#include <box2d.h>

#include "ObjectTypes.h"
#include "Texture.h"
#include "Camera.h"


//Vertex  Position
struct Vertex
{
	float x, y, z;
};

struct TexCoord
{
	float u, v;
};

//Color
struct Color
{
	DWORD color;
};

struct PolyPos
{
	float x, y;
};

//typedef string
typedef std::basic_string<TCHAR> tstring;

class Camera;

//Base Class For Game Objects
class Entity
{

	protected:
								///A matrix multipled to effect the entities with a camera
		D3DXMATRIXA16 cameraMatrix;
								///the created joint definition (connecrs object together)
		b2Joint * djoint;
								///the created joint definition (connecrs object together)
		b2DistanceJointDef jointdef;
								///the created body definition (sets up it's mass and such)
		b2BodyDef bodydef;
								///the created body definition (sets up mass and uses a defined polygon for collision detection)
		b2PolygonDef * pp;
								///Ptr to world physics
		b2World * world_physics;
								///Ptr to physical body ( calculate physics )
		b2Body * phys_body;
								///body mass
		float mass;
								///body friction
		float friction;
								///body elasticity
		float restitution;
								///rotational yaw
		float yaw;
								///rotational pitch
		float pitch;
								///rotational roll
		float roll;
								///x scale
		float sx;
								///y scale
		float sy;
								///z scale
		float sz;
								///x position variable
		float x;
								///y position variable
		float y;
								///z position variable
		float z;
								///type of the object
		int shapeType;
								///Physical body type
		int physType;
								///Texture
		Texture * texture;
								///Layer
		float layer;

	public:
							///Contructor( called when initialized )
		Entity();
							///Destructor( called when deleted )
		virtual ~Entity();
														     ///Initialze Object
		virtual void init(LPDIRECT3DDEVICE9   d3ddev, b2World * world_physics = NULL);
															 ///Set Layer
		virtual void setLayer(float layer = 0.0f);
															 ///Get Layer
		virtual float GetLayer();

		/////////////////
		/////////////////
		/////////////////
														     ///SetPosition
		virtual void setPosition(float x=0.0f, float y=0.0f);
															 ///SetPosition
		virtual void setPosition(float x, float y, float z);
															 ///GetPosition
		virtual float GetXPosition();
		virtual float GetYPosition();
		virtual float GetZPosition();
															 ///GetScale
		virtual float GetScaleX();
		virtual float GetScaleY();
															 ///SetScale
		virtual void setScale(float sx=1.0f, float sy=1.0f, float sz=1.0f);
															 ///SetRotation Yaw
		virtual void setRotationYaw(float yaw);
															 ///SetRotation Pitch
		virtual void setRotationPitch(float pitch);
															 ///SetRotation Roll
		virtual void setRotationRoll(float roll);
															 ///Set Camera
		virtual void setCamera(Camera * camera);

		////////////////
		////////////////
		////////////////
															 ///Add Force
		virtual void addForce(float x, float y);
															 ///Add Rotational Force
		virtual void addRotForce(float rotationForce);
															 ///Sets the object's mass
		virtual void setMass(float mass=1.0f);
															 ///Sets the object's friction
		virtual void setFriction(float friction=1.0f);
															 ///Sets the object's elasticity
		virtual void setElastic(float restitution = 1.0f);
															 ///Connect a body
		virtual void ConnectBody(Entity * entity, int type=0);
															 ///Creates the physics and make the physics for the object active.
		virtual void createPhysics(int shapeType = BOX, int physType = NONPHYS, int numOfPoints=0, const PolyPos * pointPositions=NULL);

		/////////////////
		/////////////////
		/////////////////
															 ///Set texture
		virtual void SetTexture(Texture * texture = NULL);
															 ///Get texture
		virtual Texture * GetTexture();
															 ///Render
		virtual void Render(LPDIRECT3DDEVICE9 d3ddev);
};

#endif

///createPhysics combines bodyType and setShape function (those 2 will be deprecated) and this will be the main function the make/activate/create the physics for the entities